class Admin::RestaurantsController < Admin::AdminController
    before_action :get_restaurant,only:[:show,:edit,:destroy,:update]

    def index
      @restaurants = Restaurant.all
    end  

    def new
      @restaurant = Restaurant.new
    end
    
    def show
    end  

    def edit
    end  

    def destroy
      @restaurant.destroy
      redirect_to action: :index
    end  

    def update
      if @restaurant.update_attributes(restaurant_params)
         redirect_to action: :show,id: restaurant.id
      else
        render :new
      end  
    end  

    def create
      restaurant = Restaurant.new(restaurant_params)
      restaurant.password = "666666"
      if restaurant.save
        redirect_to action: :show,id: restaurant.id
      else 
        render :new
      end
    end  

    private
    def restaurant_params
      params.require(:restaurant).permit(:name,:description,:attachment,:phone,:address,:login)
    end  

    def get_restaurant
      @restaurant = Restaurant.find params[:id]
    end  
end
